function d=dcube(p,x1,x2,y1,y2,z1,z2)


 d = - min ( min ( min ( min ( min ( -z1+p(:,3), z2-p(:,3) ), ...
                                     -y1+p(:,2) ), ...
                                      y2-p(:,2) ), ...
                                     -x1+p(:,1) ), ...
                                      x2-p(:,1) );
